package org.example.demo.aqs.lock;

public class Test {

    MyLock lock =  new MyLock();
    int j=0;
    public void add(){
        try {
            lock.lock();
            j++;
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            lock.unlock();
        }

    }

    public static void main(String[] args) {
        Test test = new Test();

        for (int i =0;i<5;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int k = 0; k < 10000; k++) {
                        test.add();
                    }
                }
            }).start();
        }
        try {
            Thread.sleep(10000);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(test.j);
    }
}
